<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新闻列表')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: jquery-smartwizard-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse ifcomebody1">
        <form id="formId">
            <div class="select-list">
                <ul>
                    <input name="classify" id="classify"  th:value=${classify} type="hidden">
                    <li>
                        <label>标题名称 </label>
                        <input type="text" name="name" placeholder="请输入标题名称"/>
                    </li>
                    <li id="showFlag">
                        <label class="control-label">文章类型 </label>
                        <div class="yyqy">
                            <select name="type" class="form-control "
                                    th:with="type=${@dict.getType('yyqy_type')}">
                                <option value="">请选择文章类型</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                        <div class="aqyy">
                            <select name="type" class="form-control aqyy"
                                    th:with="type=${@dict.getType('aqyy_type')}">
                                <option value="">请选择文章类型</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                        <div class="jkhl">
                            <select name="type" class="form-control jkhl"
                                    th:with="type=${@dict.getType('jkhl_type')}">
                                <option value="">请选择文章类型</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </li>
                    <li>
                        <label>更新时间 </label>
                        <div class="input-daterange input-group">
                            <input type="text" class="time-input form-control" name="startTime" onkeyup="enterShow()" id="laydate-startTime"
                                   placeholder="开始时间"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="time-input form-control" name="endTime" onkeyup="enterShow()" id="laydate-endTime"
                                   placeholder="结束时间"/>
                        </div>
                    </li>
                    <li>
                        <a class="btn btn-chongzhi btn-rounded mr16 btn-sm" onclick="$.form.reset()">重置</a>
                        <a class="btn btn-chaxun  mr16 btn-rounded btn-sm" onclick="$.table.search()">查询</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>

    <div class="btn-group-sm" style="display: flex;" id="toolbar" role="group">
        <a class="btn btn-dataadd" onclick="$.operate.add()" shiro:hasPermission="ydz:otherNews:add">
            <i class="fa fa-plus"></i> 添加
        </a>
        <a class="btn btn-newadd single disabled" onclick="$.operate.edit()"
           shiro:hasPermission="ydz:otherNews:edit">
            <i class="fa fa-edit"></i> 修改
        </a>
        <a class="btn btn-newadd multiple disabled" onclick="$.operate.removeAll()"
           shiro:hasPermission="ydz:otherNews:remove">
            <i class="fa fa-remove"></i> 删除
        </a>
        <a class="btn btn-newadd" onclick="$.table.exportExcel()" shiro:hasPermission="ydz:otherNews:export">
            <i class="fa fa-download"></i> 导出
        </a>
    </div>
    <div class="col-sm-12 select-table table-striped ifcomebody">
        <table id="bootstrap-table"></table>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: jquery-smartwizard-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('ydz:otherNews:edit')}]];
    var removeFlag = [[${@permission.hasPermi('ydz:otherNews:remove')}]];
    var prefix = ctx + "ydz/otherNews";

    $(document).ready(function () {
        var classify = $("#classify").val();
        if("1"==classify){
            $("#showFlag").hide();
        }
        if("2"==classify){
            $(".aqyy").remove();
            $(".jkhl").remove();
        }
        if("3"==classify){
            $(".yyqy").remove();
            $(".jkhl").remove();
        }
        if("4"==classify){
            $(".aqyy").remove();
            $(".yyqy").remove();
        }
    })
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/"+$("#classify").val(),
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "新闻",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: true
                },
                {
                    field: 'name',
                    title: '标题',
                    width: 400,
                    widthUnit: "px",
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 26);
                    }
                },
                {
                    field: 'state',
                    title: '发布状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'recommendState',
                    title: '是否推荐',
                    formatter: function (value, row, index) {
                        return recommendOpt(row);
                    }
                },

                {
                    field: 'keyword',
                    title: '摘要',
                    width: 400,
                    widthUnit: "px",
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 26);
                    }
                },
                {
                    field: 'updateName',
                    title: '更新人名称'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-caozuo btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')">编辑</a> ');
                        actions.push('<a class="btn btn-caozuo btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')">删除</a>');
                        actions.push('<a class="btn btn-caozuo btn-xs" href="javascript:void(0)" onclick="openShow(\'' +  row.id +  '\' , \'' +  row.state +  '\')">查看</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    function openShow(id,releaseState){
        //发布状态 （1.未发布；2.已发布）
        if (releaseState == 0){
            $.modal.alertWarning("暂未启用...");
        }else if(releaseState == 1){
            window.open("https://www.1blv.cn/qtxwxq/" + id + ".html")
        }
    }
    function recommendOpt(row) {
        if (row.recommendState == 1) {
            return '<img class="list-switch" src="/img/list-switch1.svg" onclick="reState(\'' + row.id + '\')"></img> ';
        } else {
            return '<img class="list-switch" src="/img/list-switch2.svg" onclick="cosState(\'' + row.id + '\')"></img> ';
        }
    }

    function reState(id) {
        $.modal.popUpConfirm("确认要取消推荐吗？", function () {
            var jsons = {"id": id, "recommendState": 0};
            var jsonvalue = JSON.stringify(jsons)
            save(prefix + "/editState", jsonvalue);

        })
    }

    function cosState(id) {
        $.modal.popUpConfirm("确认要启用推荐吗？", function () {
            var jsons = {"id": id, "recommendState": 1};
            var jsonvalue = JSON.stringify(jsons)
            save(prefix + "/editState", jsonvalue);

        })
    }

    /*发布状态显示 */
    function statusTools(row) {
        if (row.state == 1) {
            return '<img class="list-switch" src="/img/list-switch1.svg" onclick="disable(\'' + row.id + '\')"></img> ';
        } else {
            return '<img class="list-switch" src="/img/list-switch2.svg" onclick="enable(\'' + row.id + '\')"></img> ';
        }
    }

    /* 未发布 */
    function disable(id) {
        $.modal.popUpConfirm("确认要取消发布吗？", function () {
            var jsons = {"id": id, "state": 0};
            var jsonvalue = JSON.stringify(jsons)
            save(prefix + "/editState", jsonvalue);

        })
    }

    /* 已发布 */
    function enable(id) {
        $.modal.popUpConfirm("确认要启用发布吗？", function () {
            var jsons = {"id": id, "state": 1};
            var jsonvalue = JSON.stringify(jsons)
            save(prefix + "/editState", jsonvalue);

        })
    }

    function save(url, data, callback) {
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            headers: {
                'Content-Type': 'application/json;charset=utf8'
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍候...");
                $.modal.disable();
            },
            success: function (result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                $.operate.successCallback(result);
            }
        };
        $.ajax(config)
    }
</script>
</body>
</html>